# 进程，加锁，消息队列
from multiprocessing import Queue,Process

def save_to_queue(index, my_queue):
    my_queue.put(index)
    print(my_queue)


if __name__ == "__main__":
    process_array = []
    my_queue = Queue()
    for i in range(10):
        p = Process(target=save_to_queue, args=(i, my_queue))
        process_array.append(p)
        p.start()
    for p in process_array:
        p.join()

    while True:
        print(my_queue.get())

# <multiprocessing.queues.Queue object at 0x0000019C5D1CE220>
# <multiprocessing.queues.Queue object at 0x000002A2C646E220>
# <multiprocessing.queues.Queue object at 0x0000019BA812E220>
# <multiprocessing.queues.Queue object at 0x00000200D01FE220><multiprocessing.queues.Queue object at 0x000001AB63C3E220>
#
# <multiprocessing.queues.Queue object at 0x0000026B9396E220>
# <multiprocessing.queues.Queue object at 0x00000184B434E220>
# <multiprocessing.queues.Queue object at 0x000002514211E220>
# <multiprocessing.queues.Queue object at 0x0000016C4633E220>
# <multiprocessing.queues.Queue object at 0x0000021BBF7FE220>
# 0
# 1
# 4
# 2
# 3
# 6
# 8
# 5
# 9
# 7